package com.xored.glance.internal.utils;

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

/**
 * @author Yuri Strot
 *
 */
public class UIUtils {
	
	public static Display getDisplay() {
		return PlatformUI.getWorkbench().getDisplay();
	}
	
	public static void asyncExec(final Control control, final Runnable runnable) {
		if (control != null && !control.isDisposed()) {
			control.getDisplay().asyncExec(new Runnable() {
				public void run() {
					if (!control.isDisposed())
						runnable.run();
				}
			});
		}
	}
	
	public static void asyncExec(final Display display, final Runnable runnable) {
		if (display != null && !display.isDisposed()) {
			display.asyncExec(new Runnable() {
				public void run() {
					if (!display.isDisposed())
						runnable.run();
				}
			});
		}
	}

}
